// localStorage ------------------------
export const setLocal = (key, val) => {
  let str = '';
  if (typeof val === 'object') {
    // 由于 localStorage 只能存储字符串遇数组或对象必须转换
    // eslint-disable-next-line no-param-reassign
    str = JSON.stringify(val); // 转换JSON字符串
  } else {
    str = val;
  }
  localStorage.setItem(key, str);
};

export const getLocal = (key) => {
  const val = localStorage.getItem(key);
  try {
    return JSON.parse(val);
  } catch (error) {
    return val;
  }
};
export const delLocal = (key) => {
  localStorage.removeItem(key);
};
